﻿@{
    ViewBag.Title = "Card";
}

<div id="valuesContainer">
    <div class="tabContent">
        <table>
        @foreach (var item in ViewBag.CardForm)
        {
            String type = item.Type.ToString();
                <tr>
                    <th>
                        @item.Caption :
                    </th>
                    <td>

                        @switch (type)
                        {
                            case "string":
                            <input type="text" value="@item.Value" id="@item.Name" class="strings" name="myInput"/><br />
                                break;
                            case "bool":
                            <input type="checkbox" value="@item.Value" class="checktrue strings" name="allcheck" id="@item.Name"/><br />
                                break;
                            case "file":
                            <input type="file" value="@item.Value" class="strings" name="fileUploader" id="@item.Name"/><br />
                                break;
                            case "int":
                            <input type="number" value="@item.Value" class="strings" name="myInput" id="@item.Name"/><br />
                                break;
                            <input type="text" value="@item.Value" id="@item.Name" class="strings" name="myInput"/>
                        }
                    </td>
                </tr>  
            }
        </table>

    </div>

    <div class="actionItems">
        <button class="btn btn-primary btn-md" role="button" onclick="SaveAppSettings()">Save</button>
        <button class="btn btn-primary btn-md" role="button" onclick="location.href='/'">Close</button>
    </div>
</div>

<script>
    var appSettings = [];
    $('input[name=myInput]').change(function () {
        var d = {
            Name: this.id,
            Value: this.value,
            ScreenGroup: 'Card'
        };
        appSettings.push(d);
    });
    $('input[name=allcheck]').change(function () {
        var d = {
            Name: this.id,
            Value: $(this).is(":checked"),
            ScreenGroup: 'Card'
        };
        appSettings.push(d);
    });

    function SaveAppSettings() {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: '@Url.Action("UpdateAppSettings", "SiteSetup")',

            data: JSON.stringify({ appSettings: appSettings }),

            dataType: "json",

            beforeSend: function () { },

            success: function (data) {
                appSettings = [];


            }
        });
    }
    $(document).ready(function () {
        $('input[name="allcheck"]').each(function (index) {
            if ($(this).val().toLowerCase() == "true")

                ($(this).prop('checked', true));
        });
    });
</script>


